package net.ycxinxing.mcpebox;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.Button;
import java.util.ArrayList;
import java.util.List;

abstract public class mDialog
{
	private AlertDialog.Builder dlg;
	private View view;
	private Context ctx;
	private AlertDialog ad;
	public mDialog(Context ctx)
	{
		dlg=new AlertDialog.Builder(ctx);
		this.ctx=ctx;
		view=new View(ctx);
	}
	public void close()
	{
		ad.dismiss();
	}
	public void setCanClose(boolean p0)
	{
		dlg.setCancelable(p0);
		// TODO: Implement this method
	}

	public void setList(List<String> arr)
	{
		String[] s = new String[arr.size()];
		s = arr.toArray(s);
		dlg.setItems(s, new DialogInterface.OnClickListener(){
				@Override
				public void onClick(DialogInterface p1, int p2)
				{
					onButtonClick(p2);
					// TODO: Implement this method
				}
			});
		// TODO:Implement this method
	}
	public void show()
	{
		ad=dlg.create();
		ad.show();
	}
	public void setView(View v)
	{
		view=v;
		dlg.setView(view);
	}
	public void setTitle(String str)
	{
		dlg.setTitle(str);
	}
	public void setButton1(String msg)
	{
		dlg.setNeutralButton(msg, new DialogInterface.OnClickListener(){

				@Override
				public void onClick(DialogInterface p1, int p2)
				{
					onButtonClick(0);
					// TODO: Implement this method
				}
			});
	}
	public void setButton2(String msg)
	{
		dlg.setNegativeButton(msg, new DialogInterface.OnClickListener(){

				@Override
				public void onClick(DialogInterface p1, int p2)
				{
					onButtonClick(1);
					// TODO: Implement this method
				}
			});
	}
	public void setButton3(String msg)
	{
		dlg.setPositiveButton(msg, new DialogInterface.OnClickListener(){

				@Override
				public void onClick(DialogInterface p1, int p2)
				{
					onButtonClick(2);
					// TODO: Implement this method
				}
			});
	}
	public abstract void onButtonClick(int i)
	public Button getButton(int i)
	{
		Button btn=null;
		switch(i)
		{
			case 0:
				btn=ad.getButton(DialogInterface.BUTTON_NEUTRAL);
				break;
			case 1:
				btn=ad.getButton(DialogInterface.BUTTON_NEGATIVE);
				break;
			case 2:
				btn=ad.getButton(DialogInterface.BUTTON_POSITIVE);
				break;
		}
		return btn;
	}
	public void setMsg(String msg)
	{
		dlg.setMessage(msg);
	}
	public void setItem()
	{
		
	}
}
